package day3.homework;

import java.util.concurrent.locks.ReentrantLock;

public class Seller implements Runnable {
    private int cup = 100;
    private Object object = new Object(); //同步代码块
    private ReentrantLock lock = new ReentrantLock();

    static int count = 0;
    int num = 0;

    @Override
    public void run() {
        while (true) {
            //synchronized (object) {
            if (cup > 0) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (Thread.currentThread().getName().equals("实体店")) {
                    count++;
                } else {
                    num++;
                }
                System.out.println(Thread.currentThread().getName() + "===" + cup--);
                if (cup == 0) {
                    System.out.println("实体店卖出" + count + "个");
                    System.out.println("官网卖出" + num + "个");
                    break;
                }
            }
        }
    }

}

